package com.example.yingjiguanli_demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.yingjiguanli_demo.aspect.interfaces.RateLimiter;
import com.example.yingjiguanli_demo.aspect.interfaces.RequirePermission;
import com.example.yingjiguanli_demo.mapper.RankingsMapper;
import com.example.yingjiguanli_demo.pojo.Rankings;
import com.example.yingjiguanli_demo.pojo.Result;
import com.example.yingjiguanli_demo.pojo.UserRankingDTO;
import com.example.yingjiguanli_demo.service.IRankingsService;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author scj
 * @since 2024-11-04
 */
@Service
public class RankingsServiceImpl extends ServiceImpl<RankingsMapper, Rankings> implements IRankingsService {
    @Autowired
    private RankingsMapper userRankingMapper;

    /***
     * 根据题目获取排行榜
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return Result<List<UserRankingDTO>>
     */
    @Override
    public Result<List<UserRankingDTO>> getRankingsByQuestions(int pageNum, int pageSize) {
        // 确定偏移量
        int offset = (pageNum - 1) * pageSize;

        // 调用查询方法，获取数据
        List<UserRankingDTO> userRankings = userRankingMapper.getRankingsByQuestions(offset, pageSize);

        // 处理查询结果
        if (userRankings == null || userRankings.isEmpty()) {
            return Result.forbidden("没有找到数据");
        }

        return Result.success(userRankings);
    }
}
